<template>
    <div>
        <img-import-service ref="imgService" :options="row" @result="imgResultAction"></img-import-service>
        <Row class="add-header" type="flex" justify="space-between">
            <Col>
                <Button type="warning" @click="imgPiLiangShow">图片批量导入</Button>
            </Col>
            <Col>
                <common-save-btn ref="commonSaveBtn" :form-data="formData" @saveAction="saveAction"></common-save-btn>
            </Col>
        </Row>
        <Divider dashed class="divider"/>
        <Tabs :value="name" name="tab1">
            <TabPane label="(一)履历材料" name="0">
                <lv-li-info :form-item="formData"></lv-li-info>
            </TabPane>

            <TabPane label="(二)自传和思想材料" name="1" tab="tab1">
                <zi-zhuan-info :form-item="formData"></zi-zhuan-info>
            </TabPane>

            <TabPane label="(三)考核鉴定材料" name="2" tab="tab1">
                <kao-he-info :form-item="formData"></kao-he-info>
            </TabPane>

            <TabPane label="(四)学历学位" name="3" tab="tab1">
                <xue-li-xue-wei-info :form-item="formData"></xue-li-xue-wei-info>
            </TabPane>

            <TabPane label="(五)政审/审计" name="4" tab="tab1">
                <zheng-shen-shen-ji-info :form-item="formData"></zheng-shen-shen-ji-info>
            </TabPane>

            <TabPane label="(六)党/团材料" name="5" tab="tab1">
                <dang-tuan-info :form-item="formData"></dang-tuan-info>
            </TabPane>

            <TabPane label="(七)表彰奖励" name="6" tab="tab1">
                <biao-zhang-jiang-li-info :form-item="formData"></biao-zhang-jiang-li-info>
            </TabPane>

            <TabPane label="(八)违规违纪材料" name="7" tab="tab1">
                <wei-gui-wei-ji-info :form-item="formData"></wei-gui-wei-ji-info>
            </TabPane>

            <TabPane label="(九)工资/任免/出国会议" name="8" tab="tab1">
                <gong-zi-ren-mian-info :form-item="formData"></gong-zi-ren-mian-info>
            </TabPane>

            <TabPane label="(十)其他材料" name="9" tab="tab1">
                <other-info :form-item="formData"></other-info>
            </TabPane>
        </Tabs>
    </div>
</template>

<script>
import LvLiInfo from '@/views/pages/record/add/components/lv-li-info/index'
import ZiZhuanInfo from '@/views/pages/record/add/components/zi-zhuan-info/index'
import KaoHeInfo from '@/views/pages/record/add/components/kao-he-info/index'
import XueLiXueWeiInfo from '@/views/pages/record/add/components/xue-li-xue-wei-info/index'
import ZhengShenShenJiInfo from '@/views/pages/record/add/components/zheng-shen-shen-ji-info/index'
import DangTuanInfo from '@/views/pages/record/add/components/dang-tuan-info/index'
import BiaoZhangJiangLiInfo from '@/views/pages/record/add/components/biao-zhang-jiang-li-info/index'
import WeiGuiWeiJiInfo from '@/views/pages/record/add/components/wei-gui-wei-ji-info/index'
import GongZiRenMianInfo from '@/views/pages/record/add/components/gong-zi-ren-mian-info/index'
import OtherInfo from '@/views/pages/record/add/components/other-info/index'
import CommonSaveBtn from '@/components/common-save-btn/index'
import ImgImportService from '@/components/img-import-service/index'
import { getRecordById } from '@/api/record'

export default {
  name: 'index',
  components: {
    CommonSaveBtn,
    OtherInfo,
    GongZiRenMianInfo,
    WeiGuiWeiJiInfo,
    BiaoZhangJiangLiInfo,
    DangTuanInfo,
    ZhengShenShenJiInfo,
    XueLiXueWeiInfo,
    KaoHeInfo,
    ZiZhuanInfo,
    LvLiInfo,
    ImgImportService
  },
  data () {
    return {
      name: '0',
      formData: {},
      row: {}
    }
  },
  methods: {
    getRecordInfo () {
      this.formData = {
        name: '测试名字',
        sex: '1',
        idcard: '211381198712180451',
        tui_xiu_date: '2010-09-10',
        work_name: '鼓风机企业',
        yang_lao_no: '209323232',
        she_bao_zhong_xin: '沈河区社保中心',
        li_shu_guan_xi: 1,
        remark: '说明',
        state: '1',
        login_name: 'L0002',
        one_one: '',
        one_three: '',
        one_two: 'http://120.27.63.37:9864/webhdfs/v1/house//Wl//1.png?op=OPEN&namenoderpcaddress=hadoop01:9000&offset=0,'
      }
    },
    imgPiLiangShow () {
      this.row = {}
      this.$refs.imgService.modelAction()
    },
    imgResultAction (data) {
      this.formData = Object.assign({}, this.formData, data)
    },
    saveAction () {
      console.log(this.formData.tui_xiu_date)
      // this.formData.tui_xiu_date = this.$common.xeUtils.toDateString(this.formData.tui_xiu_date, 'yyyy/MM/dd')
      if (this.formData.name === '' || this.formData.name === undefined) {
        this.$Message.error('姓名不能为空！')
      } else {
        if (!this.$common.identityCodeValid(this.formData.idcard)) {
          this.$Message.error('身份证不合法！')
        } else {
          if (this.formData.tui_xiu_date === 'NaN-NaN-NaN') {
            this.$Message.error('退休时间不能为空！')
          } else {
            this.dateZh(this.formData.tui_xiu_date)
            this.$refs.commonSaveBtn.saveForm(this.formData)
            this.$router.push({ path: '/record/list' })
          }
        }
      }
    },
    dateZh (value) {
      var time = new Date(value)
      var y = time.getFullYear()
      var m = time.getMonth() + 1
      var d = time.getDate()
      this.formData.tui_xiu_date = y + '-' + m + '-' + d
    }
  },
  mounted () {
    if (this.$route.query.what === 'add') {
      // this.getRecordInfo()
    } else {
      getRecordById(this.$route.query.id).then(ret => {
        if (ret.data.errcode === 0) {
          this.formData = ret.data.data
        } else {
          this.$Message.error('获取信息失败，请检查网络！')
        }
      })
    }
  }
}
</script>

<style scoped>
    .add-header {
        margin-bottom: 10px;
    }
</style>
